package com.cinema.web;

import com.cinema.dao.FilmDao;
import com.cinema.dao.HallDao;
import com.cinema.entity.Hall;
import com.cinema.service.FilmService;
import com.cinema.service.HallService;
import com.cinema.util.HttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/hall")
//获取对应电影的上映信息
public class HallController {

    @Autowired
    private HallService hallService;
    @Autowired
    private FilmService filmService;
    @RequestMapping(value = "/gethalllist")
    @ResponseBody
    private Map<String,Object> getHallList(HttpServletRequest request){

        //新建map容器存储数据
        Map<String,Object> modelMap = new HashMap<>();
        List<Hall> hallList = new ArrayList<>();
        //获取前端传入的电影名信息
        String filmNameStr = HttpUtil.getString(request,"filmName");
        int filmId = filmService.queryFilmIdByName(filmNameStr);
        //如果电影名不为空
        if (filmNameStr != null){
            hallList = hallService.queryByFilmId(filmId);
            //判断是否有此电影的影厅信息
            if (hallList.size() > 0){
                //将对应电影的影厅列表信息存入map
                modelMap.put("success",true);
                modelMap.put("hallList",hallList);
            }else {
                modelMap.put("success",false);
                modelMap.put("errMsg","没有此电影的播放信息");
            }
        }else {
            modelMap.put("errMsg","不存在此电影");
        }
        return modelMap;
    }
}
